const { createProxyMiddleware } = require("http-proxy-middleware");
const base = require("./api/base");

module.exports = (app) => {
  let target;
  if (process.env.NODE_ENV === "development") target = base.development;
  else if (process.env.NODE_ENV === "debug") target = base.debug;
  else if (process.env.NODE_ENV === "production") target = base.production;

  app.use(
    createProxyMiddleware("/api", {
      target,
      secure: false,
      changeOrigin: true,
      pathRewrite: {
        "^/api": "/",
      },
    }),
  );
};
